﻿using System;
using ArtMath.Resource;
using ArtMath.Component.Point;
using ArtMath.Attribute;
using ArtMath.Core.Data;

namespace ArtMath.Component.Circle
{
    /// <summary>
    /// 直径圆
    /// </summary>
    [Serializable]
    public class DiameterCircle : FullCircleBase
    {
        public DiameterCircle(SketchPad pad, string name, bool addToList = true) : base(pad, name, ToolTypeName.zjy, addToList)
        {
            InPoints = new PointBase[2];
        }

        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}+{1}1", "Diameter", "EndPoint")]
        public PointBase DiameterPoint1
        {
            get { return InPoints[0]; }
            set { SetPoint(0, value); }
        }
        [MultilingualCategory("Structure"), MultilingualDisplayName("{0}+{1}2", "Diameter", "EndPoint")]
        public PointBase DiameterPoint2
        {
            get { return InPoints[1]; }
            set { SetPoint(1, value); }
        }
        public override PointD NewPCenter
        {
            get
            {
                return (DiameterPoint1.NewPxy + DiameterPoint2.NewPxy) / 2;
            }
        }
        public override PointD NewCenter
        {
            get
            {
                return (DiameterPoint1.NewXY + DiameterPoint2.NewXY) / 2;
            }
        }
        public override double NewRadius
        {
            get
            {
                return DiameterPoint1.NewXY.DistanceTo(DiameterPoint2.NewXY) / 2;
            }
        }
        public override void ComponentBuilding(Base component)
        {
            if (DiameterPoint1 == null) return;
            pske.Center = (DiameterPoint1.Pxy + SpareCoordinate) / 2;
            PointD xy = Pad.PxyToXY(SpareCoordinate);
            ske.Center = (DiameterPoint1.ToPointD() + xy) / 2;
            Radius = Center.DistanceTo(DiameterPoint1.ToPointD());
            ShowStatus($"{Resources.Translate("Creating")}{Resources.ColonSeparate}{Name}{Resources.LeftParenthesis}{string.Format(Resources.Translate("Of"), Resources.JoinLocalizedString("Diameter", "EndPoint") + "2", Resources.Translate("Coordinate"))}{Resources.ColonSeparate}{Pad.PxyToMath(SpareCoordinate)}");
            base.ComponentBuilding(component);
        }
        //public override void ComponentChanged(ShapeBase component)
        //{
        //    pske.Center = NewPCenter;
        //    ske.Center = NewCenter;
        //    Radius = NewRadius;
        //    base.ComponentChanged(component);
        //}
        public override void CreateComponents()
        {
            if (DiameterPoint1 == null)
            {
                DiameterPoint1 = Pad.CreatePoint(Resources.JoinLocalizedString("Diameter", "EndPoint") + "1", SpareCoordinate_);
                Pad.TrackObj = this;
            }
            else
            {
                DiameterPoint2 = Pad.CreatePoint(Resources.JoinLocalizedString("Diameter", "EndPoint") + "2", SpareCoordinate_);
                base.CreateComponents();
            }
        }
    }
}
